﻿using MDT.LifeSewagePlatform.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.Extensions.Configuration;

namespace MDT.LifeSewagePlatform.Mysql
{
    public class MysqlBase: DbContext, IMysqlDBBase
    {
        private readonly IConfiguration _config;
        public MysqlBase(IConfiguration config) 
        {
            _config = config;
        }
        public DbSet<RoleEntity> Roles { get; set; }
        public DbSet<UserEntity> Users { get; set; }
        public DbSet<DetailEntity> Details { get; set; }
        public DbSet<FileEntity> Files { get; set; }
        public DbSet<PlaceDutyEntity> PlaceDutys { get; set; }
        public DbSet<DrugEntity> Drug { get; set; }
        public DbSet<DrugDetailEntity> DrugDetail { get; set; }
        public DbSet<AlaramEntity> Alarm { get; set; }
        public DbSet<SetAlarmEntity> SetAlarm { get; set; }
        public DbSet<AlaramPlaceEntity> AlaramPlace { get; set; }
        public DbSet<CompanyEntity> Company { get; set; }

        public DbSet<DrugDayEntity> DrugDays { get; set; }

        public DbSet<RegionEntity> Regions { get; set; }

        public DbSet<IpAddressEntity> IpAddress { get; set; }

        public DbSet<AlaramRuleEntity> AlaramRules { get; set; }
        public DbSet<RuleCompanyEntity> RuleCompany { get; set; }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }


        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {

            //LoggerFactory MyLoggerFactory = new LoggerFactory();
            //var conoleLog = new ConsoleLoggerProvider(_conoptions);
            //MyLoggerFactory.AddProvider(conoleLog);//MySqlConnection
            string ConnectionStr = _config.GetSection("ConnectionStrings").GetSection("MySqlConnection").Value;
            optionsBuilder.UseMySql(ConnectionStr, ServerVersion.AutoDetect(ConnectionStr));
           
        }

        public ChangeTracker GetChangeTracker()
        {
            return base.ChangeTracker;
        }
    }
}
